package com.cskaoyan.market.shiro;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.Serializable;

@Component
public class MarketSessionManager extends DefaultWebSessionManager {
    private static final String ADMIN_TOKEN = "X-Cskaoyanmarket-Admin-Token";

    private static final String WX_TOKEN = "X-CskaoyanMarket-Token";

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        String headerAdmin = WebUtils.toHttp(request).getHeader(ADMIN_TOKEN);
        String headerWx = WebUtils.toHttp(request).getHeader(WX_TOKEN);
        if(headerAdmin != null){
            return headerAdmin;
        }
        else if (headerWx != null)
        {
            return  headerWx;
        }
        return super.getSessionId(request, response);
    }
}
